package com.travel.admin.util.prewarn;

import com.travel.admin.enums.LogLevelEnum;
import com.travel.admin.exception.TravelExceptionCode;
import com.travel.admin.thread.PreWarnThread;
import com.travel.admin.util.LogUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @desc:  微服务预警通知
 */
@Component
public class PreWarnUtil {

    @Autowired
    private ChatBotSend chatBotSend;

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private ThreadPoolExecutor sixteenThreadPool;

    @Value("${limit.num.warn}")
    private Integer limitNum;


    public void warn(String method, TravelExceptionCode zlcpdExceptionCode){
        try {
            sixteenThreadPool.execute(new PreWarnThread(chatBotSend, redisTemplate, method, zlcpdExceptionCode,limitNum));
        } catch (Exception e) {
            LogUtil.addLog(LogLevelEnum.ERROR,"发送预警信息异常{}",e);
        }
    }
}
